﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width,user-scalable=0"/>
    <meta charset="UTF-8">
    <title>BD健身</title>
    <script src="/api/js/fontSize.js"></script>
    <link rel="stylesheet" href="/api/css/bootstrap.min.css">
    <link rel="stylesheet" href="/api/css/reset.css">
    <link rel="stylesheet" href="/api/css/my_main.css">
    <script src="/assets/js/jquery.min.js"></script>
    <script src="/assets/layui.js""></script>
</head>
<body>
<div class="register">

        <div class="regTitle">
            <h2>忘记密码</h2>
        </div>
        <div class="reg_form">

            <form action="#" onsubmit="return false" class="form-horizontal">
                <div class="form-group">
                    <div class="icon">
                        <img src="/api/images/user_icon.png">
                    </div>
                    <input type="tel" name="telphone" class="form-control" placeholder="请输入手机号" id='tel'>
                </div>

                <div class="form-group">
                    <div class="icon">
                        <img src="/api/images/code_icon.png">
                    </div>
                    <input type="text" name="code" class="form-control" id='code' placeholder="验证码">
                    <a href="javascript:" id="getsms">获取验证码</a>
                </div>
                <div class="container">
                <button class="btn btn-primary"  type="submit" id="nex">下一步</button>
                </div>

            </form>
        </div>



</div>
<script type="text/javascript">
$(function(){
	//$('div a').attr('disabled',false);
	$('#nex').hover(function(){
		var telphone=$('#tel').val();
		var length=telphone.length;
		var code=$('#code').val();
		//console.log(length);
		if(length&&code){
			$('#nex').attr('disabled',false);
		}
	});
	var layer;
	layui.use('layer', function(){
		   layer = layui.layer;
		  
		 
		});
	$('#nex').click(function(){
		
		var telphone=$('#tel').val();
		var length=telphone.length;
		var code=$('#code').val();
		var url="/api/user/checkTextValidateCodes";
		var data={telphone:telphone,code:code};
		
		//console.log(telphone);
		//console.log(length);
		if(telphone&&code){
			$.post(url,data,function(res){
				var obj=eval('('+ res +')');
				var status=obj.status;
				var info=obj.info;
				if(status==400){
					//var url="/api/user/modifyPwd";
					//window.location.href=url+"?telphone="+telphone;
					layer.msg(info,{icon:5});
					/**$.get('/api/user/checkUserAccount',{telphone:telphone},function(res){
						var o=eval('('+ res +')');
						if(o.status==0){
							layer.msg('用户账号不存在',{icon:5});
						}else{
							window.location.href=obj.data+"?telphone="+telphone;
						}**/
					//})
				}else if(status==-1){
					layer.msg(info,{icon:5});
				}else{
					//当填写的手机号正确 验证码正确 这个时候需要进行真的验证账号手机号是否存在
					$.get('/api/user/checkUserAccount',{telphone:telphone},function(res){
						var o=eval('('+ res +')');
						if(o.status==0){
							layer.msg('用户账号不存在',{icon:5});
							return false;
						}else{
							window.location.href=obj.data+"?telphone="+telphone;
						}
					})
					
				}
			})
			
		}else{
			 
			layer.msg('手机号/验证码必须填写',{icon:6});
			return false;
		}
	
	});
	$("#getsms").click(function(){
		
		 var mobile=$('#tel').val();
		 //validatemobile(mobile);
		 layui.use('layer', function(){
     var layer = layui.layer;
  
}); 
		 $.get('/api/user/getTextValidateCode',{telphone:mobile},function(data){
			 var obj=eval('(' + data +')');
			 var msg=obj.info;
			// console.log(obj);
			 if(obj.status==414){
				 layer.msg(msg, {
					  icon: 5,
					  time: 3000 //2秒关闭（如果不配置，默认是3秒）
					}, function(){
					  //do something
					  //$('#tel').val('');
					});   
				
			 }else if(obj.status==200){
				 layer.msg(msg, {icon: 6}); 
			 }else{
				 layer.msg(msg, {icon: 5}); 
			 }
		 })
	   // var get_code=$("#getsms");
	    //sin(get_code);
	});
})

</script>

</body>
</html>